<?php
/**
 * 消息推送驱动器：APP
 * 
 * @date	2017年7月19日 上午10:00:30
 * 
 * @link https://codeigniter.org.cn/user_guide/general/creating_drivers.html
 *
 * @link http://tominator.comper.sk/2011/01/guide-to-codeigniter-drivers/ (教程有问题，可能已过时！)
 */
// I. Making file structure

// Make sure it extends CI_Driver_Library.
class MessagePusherApp extends CI_Driver_Library implements libraries\common\MessagePusherInterface
{
	/**
	 * Valid drivers
	 *
	 * @var array
	 */
	protected $valid_drivers = array(
		'JPush',
		'GeTui',
		'Umeng',
	);
	
	/**
	 * Reference to the driver
	 *
	 * @var string
	 */
	protected $pushProvider = 'dummy';
	
	/**
	 * medium channelConfig
	 *
	 * @var array
	 */
	protected $channelConfig = [];
	
	public function __construct($config = array())
	{
		isset($config['pushProvider']) && $this->pushProvider = $config['pushProvider'];
		isset($config['channelConfig']) && $this->channelConfig = $config['channelConfig'];
		
		if(is_array($this->channelConfig)) {
			foreach($this->channelConfig as $key => $value) {
				// MARK pushProvider.configKey: public or __set
				$this->{$this->pushProvider}->{$key} = $value;
				// MARK pushProvider.configKey: public or __get
				// var_dump($this->{$this->pushProvider}->{$key});
			}
		}
	}
	
	public function pushPerform($data)
	{
		$this->{$this->pushProvider}->pushPerform($data);
	}
	
	public function getStatus()
	{
		return $this->{$this->pushProvider}->getStatus();
	}
	
	public function getMessage()
	{
		return $this->{$this->pushProvider}->getMessage();
	}
	
}